import React from 'react'
import { Navigate, Outlet } from 'react-router-dom'

import Login from 'pages/Login'
import Register from 'pages/Register'
import AuthRequire from 'components/AuthRequire'
import Frame from 'components/Frame'

/** 保持 React.lazy 懒加载机制 */
const MapManage = React.lazy(() => import('pages/MapManage'))
const ThreeDManage = React.lazy(() => import('pages/ThreeDManage'))
const TaskManage = React.lazy(() => import('pages/TaskManage'))
const SettingManage = React.lazy(() => import('pages/SettingManage'))

const routes = [
  {
    path: '/login',
    element: <Login />
  },
  {
    path: '/register',
    element: <Register />
  },
  {
    path: '/',
    // 根路径重定向到原layout/map路径（现在为/map）
    element: <Navigate to="/map" />
  },
  {
    // 原layout层功能整合到根路径下，保持AuthRequire和Frame包裹
    path: '/',
    element: <AuthRequire><Frame><Outlet /></Frame></AuthRequire>,
    children: [
      {
        path: '/map',
        element: <MapManage />
      },
      {
        path: '/3d',
        element: <ThreeDManage />
      },
      {
        path: '/task',
        element: (
          <React.Suspense>
            <TaskManage />
          </React.Suspense>
        )
      },
      // 原setting/manage层路径简化为/setting
      {
        path: '/setting',
        element: (
          <SettingManage>
            <Outlet />
          </SettingManage>
        ),
        children: [
          // 原setting/manage默认路由重定向到设备管理
          {
            path: '/setting',
            element: <Navigate to="/setting/device" />
          },
          {
            path: '/setting/device',
            element: <div>机器设备</div>
          },
          {
            path: '/setting/arm',
            element: <div>机械臂列表</div>
          },
          {
            path: '/setting/map',
            element: <div>地图管理</div>
          }
        ]
      },
      // 404路由（原layout下的子路由404）
      {
        path: '*',
        element: <div>Page Not Found</div>
      }
    ]
  },
  // 全局404路由
  {
    path: '*',
    element: <div>Page Not Found</div>
  }
]

export default routes